<?php

/**
 * template name: Temp Register
 * description: impletement drawing of user
 * @author Tham NN  date 26/12/14
 */
$suscessful = 0;
//get all state
$aStates = Country::getAllState();

if (isset($_POST['bt_register'])) {
     
//    if ($_POST['security_code'] == $_SESSION['code2']) {
        $user = new User();
        $data['first_name'] = $_REQUEST['txt_name'];
        $data['location'] = $_REQUEST['txt_location'];
        $data['last_name'] = $_REQUEST['txt_lastname'];
        $data['password'] = $_REQUEST['txt_password'];
        $data['email'] = $_REQUEST['txt_email'];
        $data['city'] = $_REQUEST['txt_city'];
        $data['state'] = $_POST['state'];
        $data['country'] = $_POST['select_country'];
        $data['postcode'] = $_POST['txt_postcode'];
        $checkemail = User::checkUserNameByEmail($_REQUEST['txt_email']); //check if email is existed
        if ($checkemail == false) {//if this email is not existed
            $id_user_register = $user->add_user($data);
            $data['id_user_register'] = $id_user_register;
            MailHelper::sendmailRegister($data);
            $suscessful = 1;
        } else {
            if ($checkemail) {
                $suscessful = 3;
            }
        }
        ?>    
        <div class="modal fade" id="capcha-sucess" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel">Register Success</h4>
                    </div>
                    <div class="modal-body">
                        <?php
                        if ($suscessful == 1) {
                            echo 'You have registered successfully.';
                        }
                        //						Tuan comment
                        //						  if($suscessful == 2){
                        //						 echo '<span style="color:red;">Username is existed.</span>'; }
                        if ($suscessful == 3) {
                            echo '<span style="color:red;">Email is existed</span>';
                        }
                        ?>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>
        <?php
	/*
    } else {
      // echo 'Capacha sai';
       //exit();
        ?>
        <div class="modal fade" id="capcha-false" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel">Register Error</h4>
                    </div>
                    <div class="modal-body">
                        Security characters is not correctly
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>
        <?php
    }
    */
}
$user = new User();
get_header();
$country = new Country();
?>
<div class="content">
    <div class="container">
        <div class="box-main">
            <div class="row">
                <div class="col-md-9">
                   <div class="tab">
                        <a href="<?php echo get_site_url(); ?>">Home / </a> <?php echo $post->post_title ?> </div>
                    <h2><?php echo $post->post_title ?> </h2>
                    <br/>
                    <div class="text-content border-radius">


                        <form  method="post" class="frm_register" >

                            <p>
                                <label>First Name</label>
                                <input type="text"  id="txt_name" name="txt_name" value="<?php
                                if (isset($_REQUEST['txt_name'])) {
                                    echo $_REQUEST['txt_name'];
                                }
                                ?>" />
                            <p id="error_name" class="error_info"  ></p>
                            </p>
                            <p>
                                <label>Last Name</label>
                                <input type="text"  id="txt_lastname" name="txt_lastname" value="<?php
                                if (isset($_REQUEST['txt_lastname'])) {
                                    echo $_REQUEST['txt_lastname'];
                                }
                                ?>" />

                            <p id="error_lastname"  class="error_info"></p>
                            </p>
                            <?php //tuan edit   ?>
                            <p style="display: none;">
                                <label>User Name</label>
                                <input type="text"  id="txt_username" name="txt_username"  value="<?php
                                if (isset($_REQUEST['txt_lastname'])) {
                                    echo $_REQUEST['txt_username'];
                                }
                                ?>" />                                            
                            <p id="error_username"  class="error_info"></p>
                            </p>
                            <p>
                                <label>Email Address</label>
                                <input type="text" id="txt_email" name="txt_email" value="<?php
                                if (isset($_REQUEST['txt_email'])) {
                                    echo $_REQUEST['txt_email'];
                                }
                                ?>" />
                            <p id="error_email"  class="error_info"></p>
                            </p>
                            <p>
                                <label>Password</label>
                                <input type="password" id="txt_password" name="txt_password"  />
                            <p id="error_passw"  class="error_info"></p>
                            </p>
                            <p>
                                <label>Re-Password:</label>
                                <input type="password" id="txt_repassword"  name="txt_repassword" />
                            <p id="error_repassw"  class="error_info"></p>
                            </p>
                         
                            <p>
                                <label>City</label>
                                <input type="text"   value="<?php
                                if (isset($_REQUEST['txt_city'])) {
                                    echo $_REQUEST['txt_city'];
                                }
                                ?>"  id="txt_city" name="txt_city"   />
                            <p id="error_city"  class="error_info"></p>
                            </p>




                            <p>
                                <label>Country</label>
                                <select id="select_country"  name ="select_country">
                                    <?php
                                    $selectc = 1;
                                    if (isset($_REQUEST['select_country'])) {
                                        $selectc = $_REQUEST['select_country'];
                                    }
                                    echo $country->get_all_option_country();
                                    ?>
                                </select>
                            </p>

                            <p>
                                <label>State</label>
                                <span id="div_get_state">
                                    <?php
                                    $selectc2 = 1;
                                    if (isset($_REQUEST['state'])) {
                                        $selectc2 = $_REQUEST['state'];
                                    }
                                    echo $country->get_all_state_by_id_country($selectc2);
                                    ?>
                                </span>

                            <p id="error_state"  class="error_info"></p>
                            </p>

                            <p>

                                <label>Postcode</label>
                                <input type="text"  value="<?php
                                if (isset($_REQUEST['txt_postcode'])) {
                                    echo $_REQUEST['txt_postcode'];
                                }
                                ?>"   id="txt_postcode" name="txt_postcode" />
                                <input type="hidden"   name="check_add" id="check_add" value="1" />
                            <p id="error_postcode"  class="error_info"></p>
			    <?php
			    /*
                            <p>Enter the characters below</p>
                            <p>
                                <input class="capcha2" type="text" id="security_code" name="security_code" />

                                <img src="<?php bloginfo('template_directory') ?>/capcha/captcha.php" alt="captcha" />

                            <p id="error_capcha" class="error_info"></p>
                            <br /> 
			     * 
			     */?>
                            <p class="p_button_right">
                                <button onClick="return checkregister();"  type="submit" name="bt_register"  id="bt_register"  class="button">
                                    Create Your Account
                                </button>
                            </p>  
                        </form>
                    </div>
                </div>
                <?php
                include_once 'right_single.php';
                ?>
            </div>
        </div>
    </div>
</div>




<?php get_footer(); ?>

  <script type="text/javascript" language="javascript" src="<?php bloginfo('template_directory') ?>/js/jquery-1.8.2.min.js"></script>
        <script type="text/javascript" language="javascript" src="<?php bloginfo('template_directory') ?>/js/bootstrap.js"></script>
        <script type="text/javascript">
            jQuery(document).ready(function() {
                jQuery("#capcha-false").modal();
                jQuery("#capcha-sucess").modal();
            });
        </script>